home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / (Demos) / TimeCPU.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  31KB  |  1,197 lines

  1. /*
  2. TimeCPU.c
  3. Denis G. Pelli, 1991-1995
  4. This routine uses my Timer.c to measure the timing of basic CPU
  5. operations and several random number generators. (Apple's Microseconds() routine
  6. would do just as well, instead of Timer.c, but wasn't available when I wrote this.) 
  7. The timing seems to be very accurate. It ought to be as accurate as the
  8. frequency of the oscillator in the VIA chip. However, I haven't checked the
  9. timing against a known standard.
  10.  
  11. The Fixed data type is predefined by Apple as a long (i.e. 32 bits) with an assumed 
  12. decimal point in the middle.
  13.  
  14. The access to video memory overwrites a small part of your main screen, the
  15. first 40 bytes. This will be in the upper left hand corner of your display, and
  16. will usually be barely noticeable. I like seeing that, as it confirms that the
  17. program really is accessing the video memory.
  18.  
  19. This program requests a memory partition of 900K. It will run in less, but will
  20. then do fewer iterations.
  21.  
  22. NOTE: This file is part of the VideoToolbox archive of C sources for the Mac. 
  23. You can download the whole VideoToolbox from any Info-Mac mirror:
  24. ftp://mirror.apple.com/mirrors/info-mac/dev/lib/video-toolbox-95-11-10-c.hqx
  25. ftp://mirrors.aol.com/pub/info-mac/dev/lib/video-toolbox-95-11-10-c.hqx
  26.  
  27. The glue libraries NameRegistryLib and DriverServicesLib are in the VideoToolbox Libs folder. 
  28.  
  29. HISTORY:
  30. 1/91    dgp    wrote it
  31. 2/16/91    dgp    added fpu test, to fail gracefully if compiled with FPU support, but FPU
  32.             is not present.
  33. 3/4/91    dgp    added timing of random number generators
  34. 8/6/91    dgp    added timing of RandFill.
  35. 8/24/91    dgp    Made compatible with THINK C 5.0.
  36. 1/25/92    dgp    Calibrate and correct for the slowness of TimeIt(). 
  37.             Measure and subtract off the small loop overhead.
  38.             Identify machine and compiler.
  39.             Automatically append results to TimeCPU.data file.
  40. 1/29/92    dgp    Time move from memory to video memory, for showing movies.
  41.             Added transcendental functions since Radius 8881 init and System 7.01
  42.             speed them up dramatically and the Quadra is reputed to
  43.             do them very slowly.
  44. 1/30/92    dgp    Access video memory only in 32-bit mode, to avoid crashes.
  45. 8/19/92    dgp    time the 68881 instructions _sin, _sqrt, _exp, _log
  46.             Use new Timer.c instead of old TimeIt.c
  47. 8/28/92    dgp    updated to use new reentrant Timer.c
  48. 11/18/92 dgp renamed output file to “TimeCPU results”
  49. 1/11/93    dgp    check for presence of 68020. Put Gestalt tests in main, without
  50.             any fpu usage, since program was crashing when fpu was absent
  51.             before getting to the fpu test. (Supposedly that was fixed
  52.             in THINK C 5. Oh well.)
  53. 2/7/93    dgp    added timing of SetPixelsQuickly().
  54. 7/9/93    dgp check for 32-bit addressing capability.
  55. 3/13/94    dgp    added timing of short arithmetic, and put conditionals around each section.
  56. 6/1/94    dgp    added timing of BlockMoveData().
  57. 6/14/94    dgp    can32 is now computed by calling TrapAvailable(_SwapMMUMode), which 
  58.             returns the correct answer even on Macs with dirty ROMs.
  59. 7/31/94    dgp made compatible with new SANE.h in Universal Headers.
  60. 9/5/94 dgp removed assumption in printf's that int==short.
  61. 10/2/94    dgp deleted RandomX() since it's part of SANE, which doesn't exist on PowerPC,
  62.             and, in any event, was uselessly slow on 68k machines. Tidied up the
  63.             printout for readability even for computers as fast as the PowerPC.
  64. 4/9/95 dgp added a few tests relevant to nrand(). Increased n. Polished the printout a bit.
  65. 4/11/95 dgp changed declaration of bufferHandle from void ** to Handle, for compatibility with
  66. old pre-universal apple headers.
  67. 5/23/95 dgp Apple changed the prototype in the header file from SwapMMUMode(char *) to 
  68.             SwapMMUMode(signed char *). To retain compatibility with both old and new
  69.             headers, I cast the argument (void *).
  70. 11/20/95 dgp added timing of moves using float pointers, since they're supposed to be fast on the PowerPCs.
  71. 1/28/96 dgp only call BlockMoveDataUncached on PCI Macs; otherwise use BlockMoveData.
  72. 3/4/96 dgp made compatible with THINK C 7.
  73. */
  74. #include "VideoToolbox.h"
  75. #ifndef __TRAPS__
  76.     #include <Traps.h>        // _SwapMMUMode
  77. #endif
  78. //#include <Menus.h>    // DrawMenuBar
  79. void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  80. void ExpandRect(Rect *r,double hMag,double vMag);
  81. void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  82.  
  83. void TimeCPU(void);
  84. #if GENERATINGPOWERPC
  85. // BlockMoveDataUncached is only available on PowerPC. Apparently video buffers are "uncacheable" and
  86. // BlockMoveData uses an instruction that is emulated slowly in that case.
  87.     extern void BlockCopy(const void *srcPtr, void *destPtr, Size byteCount);
  88.     extern void BlockMoveDataUncached(const void *srcPtr, void *destPtr, Size byteCount);
  89. #else
  90.     #define BlockCopy BlockMoveData
  91.     #define BlockMoveDataUncached BlockMoveData
  92. #endif
  93. #if UNIVERSAL_HEADERS>1
  94.     #ifndef __CODEFRAGMENTS__
  95.         #include <CodeFragments.h>
  96.     #endif
  97. #else
  98.     #undef NO_DRIVER_SERVICES_LIB
  99.     #define NO_DRIVER_SERVICES_LIB 1
  100. #endif
  101.  
  102. void main(void)
  103. {
  104.     long value;
  105.  
  106.     Require(gestaltOriginalQD);
  107.     Gestalt(gestaltTimeMgrVersion,&value);
  108.     if(value<gestaltRevisedTimeMgr)
  109.         PrintfExit("Sorry, your System is too old; I need at least \n"
  110.             "the Revised Time Manager.\n");
  111.     TimeCPU();
  112. }
  113.  
  114. void TimeCPU(void)
  115. {
  116.     long n,quickDraw;
  117.     short i;
  118.     register long *paL,*pbL,iL,jL,kL,mL;
  119.     double x,y,z;
  120.     Fixed xF,yF,zF;
  121.     Handle bufferHandle;
  122.     void *buffer,*buffer2;
  123.     char Buffer[32];
  124.     FILE *o[2],*dataFile;
  125.     GDHandle device;
  126.     double s,s0,overhead;
  127.     Timer *timer;
  128.     OSErr osErr,error;
  129.     long value;
  130.     Boolean can32;
  131.     Boolean pci;    // Is this a PCI Mac? Only the PCI Macs have BlockMoveDataUncached.
  132.  
  133.     MaximizeConsoleHeight();
  134.     /* INITIALIZE QuickDraw */
  135.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  136.         console_options.ncols = 90;
  137.     #elif __MWERKS__
  138.         SIOUXSettings.columns=90;
  139.     #elif
  140.         InitGraf(&qd.thePort);
  141.         InitFonts();
  142.         InitWindows();
  143.         InitCursor();
  144.     #endif
  145.     printf("Welcome to TimeCPU.\n");
  146.     assert(StackSpace()>4000);
  147.     can32=TrapAvailable(_SwapMMUMode);
  148.     timer=NewTimer();
  149.     #define gestaltNameRegistryVersion 'nreg'    // support old versions of Gestalt.h
  150.     error=Gestalt(gestaltNameRegistryVersion,&value);
  151.     pci=(error==0);    // are there PCI slots?
  152.     #if CFMSYSTEMCALLS
  153.         if(GENERATINGPOWERPC && pci){
  154.             // The BlockMoveDataUncached glue is in a shared library.
  155.             // If the DriverServicesLib is weak-linked, and missing, we need to
  156.             // check for the library, to prevent a crash if we try to access the 
  157.             // library's exports.
  158.             CFragConnectionID        connID;
  159.             Ptr                        mainAddr;
  160.             Str255                    errName;
  161.             long templong;
  162.             int error;
  163.             
  164.             error=Gestalt(gestaltCFMAttr,&templong);    // Code Fragment Manager?
  165.             if(!error){
  166.                 error=GetSharedLibrary((ConstStr63Param)"\pDriverServicesLib"
  167.                     ,kAnyCFragArch,kFindCFrag,&connID,&mainAddr,errName);
  168.                 if(error)PrintfExit("\nCouldn't load %#s. GetSharedLibrary error=%d\n\007",errName,(int)error);
  169.             }
  170.         }
  171.     #endif
  172.     o[0]=stdout;
  173.     o[1]=dataFile=fopen("TimeCPU results","a");    /* Append to data file */
  174.     if(dataFile!=NULL){
  175.         printf("Key results will be appended to “TimeCPU results” file.\n\n");
  176.         SetFileInfo("TimeCPU results",'TEXT','ttxt');
  177.     }
  178.     else printf("Could not open “TimeCPU results” file\n\n");
  179.     ffprintf(o,"\n%s\n",BreakLines(IdentifyMachine(),80));
  180.     ffprintf(o,"%s\n\n",BreakLines(IdentifyCompiler(),80));
  181.     ffprintf(o,"      Time    Operation\n");
  182.     srand(clock());
  183.     y=sqrt(2.0);
  184.     z=sqrt(3.0);
  185.     kL=y*1000.;
  186.     mL=z*10.;
  187.     RandFill(Buffer,sizeof(Buffer));
  188.         
  189.     n=100000;    // REDUCE THIS NUMBER TO SPEED UP THE TESTING, BUT REDUCE PRECISION.
  190.     overhead=0.0;
  191.     StartTimer(timer);
  192.     for(iL=n/10;iL>0;iL--) ;
  193.     overhead=StopTimerSecs(timer)/n-overhead;    // the loop overhead per operation
  194.  
  195. // Time various ways of moving memory    
  196.     for(;n>0;){
  197.         bufferHandle=NewHandle(2*sizeof(long)*n);
  198.         if(bufferHandle==NULL)bufferHandle=TempNewHandle(2*sizeof(long)*n,&osErr);
  199.         if(bufferHandle!=NULL)break;
  200.         n/=2;
  201.         printf("Reducing iterations to %ld to fit in available memory.\n",n);
  202.     }
  203.     assert(bufferHandle!=NULL);
  204.     HLockHi(bufferHandle);
  205.     buffer=*bufferHandle;
  206.     buffer=(void *)(((unsigned long)buffer+15) & ~15UL);    // round up to multiple of 16
  207.     buffer2=(long *)buffer+n;
  208.     buffer2=(void *)((unsigned long)buffer2 & ~15UL);    // round down to multiple of 16
  209.     {
  210.         StartTimer(timer);
  211.         BlockMove(buffer2,buffer,4*n);
  212.         s=StopTimerSecs(timer);
  213.         ffprintf(o,"%11.3f ms    BlockMove(,,%ld);    // %.1f MB/s\n"
  214.             ,s*1e3,n*4,n*4/1024./1024./s);
  215.     }
  216.     {
  217.         StartTimer(timer);
  218.         BlockMoveData(buffer2,buffer,4*n);
  219.         s=StopTimerSecs(timer);
  220.         ffprintf(o,"%11.3f ms    BlockMoveData(,,%ld);    // %.1f MB/s\n"
  221.             ,s*1e3,n*4,n*4/1024./1024./s);
  222.     }
  223.     {
  224.         register double *paF,*pbF;
  225.  
  226.         n/=sizeof(*paF)/4;
  227.         paF=(void *)buffer;
  228.         pbF=(void *)buffer2;
  229.         StartTimer(timer);
  230.         for(iL=n/10;iL>0;iL--){
  231.             *paF++=*pbF++;
  232.             *paF++=*pbF++;
  233.             *paF++=*pbF++;
  234.             *paF++=*pbF++;
  235.             *paF++=*pbF++;
  236.             *paF++=*pbF++;
  237.             *paF++=*pbF++;
  238.             *paF++=*pbF++;
  239.             *paF++=*pbF++;
  240.             *paF++=*pbF++;
  241.         }
  242.         s=StopTimerSecs(timer)/n-overhead;
  243.         ffprintf(o,"%11.3f µs    *paF++=*pbF++;        // double, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  244.         n*=sizeof(*paF)/4;
  245.     }
  246.     {
  247.         register double *paF,*pbF;
  248.         unsigned long bytes=sizeof(*paF);
  249.  
  250.         n/=sizeof(*paF)/4;
  251.         paF=(void *)buffer;
  252.         pbF=(void *)buffer2;
  253.         paF--;pbF--;
  254.         StartTimer(timer);
  255.         for(iL=n/10;iL>0;iL--){
  256.             *++paF=*++pbF;
  257.             *++paF=*++pbF;
  258.             *++paF=*++pbF;
  259.             *++paF=*++pbF;
  260.             *++paF=*++pbF;
  261.             *++paF=*++pbF;
  262.             *++paF=*++pbF;
  263.             *++paF=*++pbF;
  264.             *++paF=*++pbF;
  265.             *++paF=*++pbF;
  266.         }
  267.         s=StopTimerSecs(timer)/n-overhead;
  268.         ffprintf(o,"%11.3f µs    *++paF=*++pbF;        // double, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  269.         n*=sizeof(*paF)/4;
  270.     }
  271.     {
  272.         register float *paF,*pbF;
  273.  
  274.         n/=sizeof(*paF)/4;
  275.         paF=(float *)buffer;
  276.         pbF=(float *)buffer2;
  277.         StartTimer(timer);
  278.         for(iL=n/10;iL>0;iL--){
  279.             *paF++=*pbF++;
  280.             *paF++=*pbF++;
  281.             *paF++=*pbF++;
  282.             *paF++=*pbF++;
  283.             *paF++=*pbF++;
  284.             *paF++=*pbF++;
  285.             *paF++=*pbF++;
  286.             *paF++=*pbF++;
  287.             *paF++=*pbF++;
  288.             *paF++=*pbF++;
  289.         }
  290.         s=StopTimerSecs(timer)/n-overhead;
  291.         ffprintf(o,"%11.3f µs    *paF++=*pbF++;        // float, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  292.         n*=sizeof(*paF)/4;
  293.     }
  294.     {
  295.         register float *paF,*pbF;
  296.  
  297.         n/=sizeof(*paF)/4;
  298.         paF=(void *)buffer;
  299.         pbF=(void *)buffer2;
  300.         paF--;pbF--;
  301.         StartTimer(timer);
  302.         for(iL=n/10;iL>0;iL--){
  303.             *++paF=*++pbF;
  304.             *++paF=*++pbF;
  305.             *++paF=*++pbF;
  306.             *++paF=*++pbF;
  307.             *++paF=*++pbF;
  308.             *++paF=*++pbF;
  309.             *++paF=*++pbF;
  310.             *++paF=*++pbF;
  311.             *++paF=*++pbF;
  312.             *++paF=*++pbF;
  313.         }
  314.         s=StopTimerSecs(timer)/n-overhead;
  315.         ffprintf(o,"%11.3f µs    *++paF=*++pbF;        // float, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  316.         n*=sizeof(*paF)/4;
  317.     }
  318.     {
  319.         paL=(void *)buffer;
  320.         pbL=(void *)buffer2;
  321.         StartTimer(timer);
  322.         for(iL=n/10;iL>0;iL--){
  323.             *paL++=*pbL++;
  324.             *paL++=*pbL++;
  325.             *paL++=*pbL++;
  326.             *paL++=*pbL++;
  327.             *paL++=*pbL++;
  328.             *paL++=*pbL++;
  329.             *paL++=*pbL++;
  330.             *paL++=*pbL++;
  331.             *paL++=*pbL++;
  332.             *paL++=*pbL++;
  333.         }
  334.         s=StopTimerSecs(timer)/n-overhead;
  335.         ffprintf(o,"%11.3f µs    *paL++=*pbL++;        // long, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paL)*1e-6/s);
  336.     }
  337.  
  338.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  339.     if(quickDraw>=gestalt8BitQD){
  340.         device=GetMainDevice();
  341.         if(device!=NULL){
  342.             paL=(long *)(**(**device).gdPMap).baseAddr;
  343.             if(paL!=NULL){
  344.                 signed char mode=true32b;
  345.                 long *pSave=paL;
  346.                 
  347.                 StartTimer(timer);
  348.                 if(can32)SwapMMUMode((void *)&mode);
  349.                 for(iL=n/10;iL>0;iL--) paL-=10;
  350.                 if(can32)SwapMMUMode((void *)&mode);
  351.                 s0=StopTimerSecs(timer)/n-overhead;
  352.                 paL=pSave;
  353.                 pbL=(long *)buffer2;
  354.                 StartTimer(timer);
  355.                 if(can32)SwapMMUMode((void *)&mode);
  356.                 for(iL=n/10;iL>0;iL--){
  357.                     *paL++=*pbL++;
  358.                     *paL++=*pbL++;
  359.                     *paL++=*pbL++;
  360.                     *paL++=*pbL++;
  361.                     *paL++=*pbL++;
  362.                     *paL++=*pbL++;
  363.                     *paL++=*pbL++;
  364.                     *paL++=*pbL++;
  365.                     *paL++=*pbL++;
  366.                     *paL++=*pbL++;
  367.                     paL-=10;
  368.                 }
  369.                 if(can32)SwapMMUMode((void *)&mode);
  370.                 s=StopTimerSecs(timer)/n-overhead;
  371.                 s-=s0;                                    // remove time for the paL-=10;
  372.                 ffprintf(o,"%11.3f µs    *paL++=*pbL++;        // long, memory to video mem. %.1f MB/s\n",s*1e6,4e-6/s);
  373.  
  374.                 {
  375.                     Boolean tryIt=1;
  376.                     char *blockMoveName;
  377.  
  378.                     //if(pci)tryIt=Choose(tryIt,"\nTry using BlockMoveDataUncached to copy from memory to video buffer?\n",noYes,2);
  379.                     //else tryIt=Choose(tryIt,"\nTry using BlockMoveData to copy from memory to video buffer?\n",noYes,2);
  380.                     if(tryIt){
  381.                         // this fails on some Macs
  382.                         if(pci)blockMoveName="BlockMoveDataUncached";
  383.                         else blockMoveName="BlockMoveData";
  384.                         paL=pSave;
  385.                         pbL=(long *)buffer2;
  386.                         BlockMoveData(paL,pbL,4*n);    // first copy from screen to memory, so we won't mess up screen
  387.                         StartTimer(timer);
  388.                         if(pci)BlockMoveDataUncached(pbL,paL,4*n);
  389.                         else BlockMoveData(pbL,paL,4*n);
  390.                         s=StopTimerSecs(timer)-overhead;
  391.                         ffprintf(o,"%11.3f ms    %s(,,%ld);    // mem.to vid.mem. %.1f MB/s\n"
  392.                             ,s*1e3,blockMoveName,n*4,n*4/1024./1024./s);
  393.                     }
  394.                     if(tryIt && pci){
  395.                         // this fails on some Macs
  396.                         blockMoveName="BlockCopy";
  397.                         paL=pSave;
  398.                         pbL=(long *)buffer2;
  399.                         BlockMoveData(paL,pbL,4*n);    // first copy from screen to memory, so we won't mess up screen
  400.                         StartTimer(timer);
  401.                         BlockCopy(pbL,paL,4*n);
  402.                         s=StopTimerSecs(timer)-overhead;
  403.                         ffprintf(o,"%11.3f ms    %s(,,%ld);    // mem.to vid.mem. %.1f MB/s\n"
  404.                             ,s*1e3,blockMoveName,n*4,n*4/1024./1024./s);
  405.                     }
  406.                 }
  407.             }
  408.         }
  409.     }
  410.     DisposeHandle(bufferHandle);
  411.     buffer=buffer2=NULL;
  412.  
  413. // Time the VideoToolbox routines that copy images (based on CopyBits and CopyBitsQuickly).
  414.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  415.     if(quickDraw>=gestalt8BitQD){
  416.         unsigned long row[256],row2[256];
  417.         int rowLength=256,clutSize;
  418.         
  419.         assert(StackSpace()>4000);
  420.         n/=100;
  421.         device=GetMainDevice();
  422.         clutSize=GDClutSize(device);
  423.         for(i=0;i<rowLength;i++)row[i]=nrand(clutSize);
  424.         StartTimer(timer);
  425.         for(iL=n;iL>0;iL--){
  426.             SetDevicePixelsQuickly(device,0,0,row,rowLength);
  427.         }
  428.         // NOTE: if you single step through this in the Debugger
  429.         // you'll get an apparent read-back error if the Debugger
  430.         // redraws the Menu bar between writing and reading the pixels.
  431.         s=StopTimerSecs(timer)/n-overhead;
  432.         GetDevicePixelsQuickly(device,0,0,row2,rowLength);
  433.         ffprintf(o,"%11.3f ms    SetPixelsQuickly(,,,,%d);// %d-bit pixels, %.3f MB/s\n",s*1e3
  434.             ,(int)rowLength,(int)(**(**device).gdPMap).pixelSize
  435.             ,(double)rowLength*(**(**device).gdPMap).pixelSize/8/1024/1024/s);
  436.  
  437.         StartTimer(timer);
  438.         for(iL=n;iL>0;iL--){
  439.             GetDevicePixelsQuickly(device,0,0,row,rowLength);
  440.         }
  441.         s=StopTimerSecs(timer)/n-overhead;
  442.         ffprintf(o,"%11.3f ms    GetPixelsQuickly(,,,,%d);// %d-bit pixels, %.3f MB/s\n",s*1e3
  443.             ,(int)rowLength,(int)(**(**device).gdPMap).pixelSize
  444.             ,(double)rowLength*(**(**device).gdPMap).pixelSize/8/1024/1024/s);
  445.         n*=100;
  446.  
  447.         for(i=0;i<1;i++)if(row2[i]!=row[i])printf("Pixel %d: wrote %ld != read %ld\n"
  448.             ,(int)i,row[i],row2[i]);
  449.  
  450.     }
  451.  
  452.     if(quickDraw>=gestalt32BitQD){
  453.         GWorldPtr aWorld,bWorld;
  454.         Rect r;
  455.         int error,pixelSize;
  456.         double pixels;
  457.  
  458.         n=2;
  459.         SetRect(&r,0,0,100,100);
  460.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  461.         error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  462.         if(!error)error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  463.         if(!error){
  464.             LockPixels(GetGWorldPixMap(aWorld));
  465.             LockPixels(GetGWorldPixMap(bWorld));
  466.             StartTimer(timer);
  467.             for(iL=n;iL>0;iL--){
  468.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&aWorld->portRect,srcCopy,NULL);
  469.             }
  470.             s=StopTimerSecs(timer)/n-overhead;
  471.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  472.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%dx%d, %.3f MB/s\n"
  473.                 ,s*1e3,(int)r.right,(int)r.bottom
  474.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  475.         }
  476.         DisposeGWorld(aWorld);
  477.         DisposeGWorld(bWorld);
  478.         SetRect(&r,0,0,100,100);
  479.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  480.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  481.         ShrinkRect(&r,20,1);
  482.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  483.         if(!error){
  484.             LockPixels(GetGWorldPixMap(aWorld));
  485.             LockPixels(GetGWorldPixMap(bWorld));
  486.             StartTimer(timer);
  487.             for(iL=n;iL>0;iL--){
  488.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopy,NULL);
  489.             }
  490.             s=StopTimerSecs(timer)/n-overhead;
  491.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  492.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  493.                 ,s*1e3
  494.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  495.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  496.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  497.         }
  498.         DisposeGWorld(aWorld);
  499.         DisposeGWorld(bWorld);
  500.         SetRect(&r,0,0,100,100);
  501.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  502.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  503.         ShrinkRect(&r,1,20);
  504.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  505.         if(!error){
  506.             LockPixels(GetGWorldPixMap(aWorld));
  507.             LockPixels(GetGWorldPixMap(bWorld));
  508.             StartTimer(timer);
  509.             for(iL=n;iL>0;iL--){
  510.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopy,NULL);
  511.             }
  512.             s=StopTimerSecs(timer)/n-overhead;
  513.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  514.             r=aWorld->portRect;
  515.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  516.                 ,s*1e3
  517.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  518.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  519.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  520.         }
  521.         DisposeGWorld(aWorld);
  522.         DisposeGWorld(bWorld);
  523.         n=100000;
  524.     }
  525.     if(quickDraw>=gestalt32BitQD){
  526.         GWorldPtr aWorld,bWorld;
  527.         Rect r;
  528.         int error,pixelSize;
  529.         double pixels;
  530.  
  531.         n=2;
  532.         SetRect(&r,0,0,100,100);
  533.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  534.         error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  535.         if(!error)error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  536.         if(!error){
  537.             LockPixels(GetGWorldPixMap(aWorld));
  538.             LockPixels(GetGWorldPixMap(bWorld));
  539.             StartTimer(timer);
  540.             for(iL=n;iL>0;iL--){
  541.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&aWorld->portRect,srcCopyLiterally,NULL);
  542.             }
  543.             s=StopTimerSecs(timer)/n-overhead;
  544.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  545.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%dx%d, %.3f MB/s\n"
  546.                 ,s*1e3,(int)r.right,(int)r.bottom
  547.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  548.         }
  549.         DisposeGWorld(aWorld);
  550.         DisposeGWorld(bWorld);
  551.         SetRect(&r,0,0,100,100);
  552.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  553.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  554.         ShrinkRect(&r,20,1);
  555.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  556.         if(!error){
  557.             LockPixels(GetGWorldPixMap(aWorld));
  558.             LockPixels(GetGWorldPixMap(bWorld));
  559.             StartTimer(timer);
  560.             for(iL=n;iL>0;iL--){
  561.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopyLiterally,NULL);
  562.             }
  563.             s=StopTimerSecs(timer)/n-overhead;
  564.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  565.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  566.                 ,s*1e3
  567.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  568.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  569.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  570.         }
  571.         DisposeGWorld(aWorld);
  572.         DisposeGWorld(bWorld);
  573.         SetRect(&r,0,0,100,100);
  574.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  575.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  576.         ShrinkRect(&r,1,20);
  577.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  578.         if(!error){
  579.             LockPixels(GetGWorldPixMap(aWorld));
  580.             LockPixels(GetGWorldPixMap(bWorld));
  581.             StartTimer(timer);
  582.             for(iL=n;iL>0;iL--){
  583.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopyLiterally,NULL);
  584.             }
  585.             s=StopTimerSecs(timer)/n-overhead;
  586.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  587.             r=aWorld->portRect;
  588.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  589.                 ,s*1e3
  590.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  591.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  592.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  593.         }
  594.         DisposeGWorld(aWorld);
  595.         DisposeGWorld(bWorld);
  596.         n=100000;
  597.     }
  598.  
  599.     if(1){            // time long arithmetic
  600.         StartTimer(timer);
  601.         for(iL=n/10;iL>0;iL--){
  602.             jL=kL;
  603.             jL=kL;
  604.             jL=kL;
  605.             jL=kL;
  606.             jL=kL;
  607.             jL=kL;
  608.             jL=kL;
  609.             jL=kL;
  610.             jL=kL;
  611.             jL=kL;
  612.         }
  613.         s=StopTimerSecs(timer)/n-overhead;
  614.         ffprintf(o,"%11.3f µs    jL=kL;            // long, register to register\n",s*1e6);
  615.     
  616.         StartTimer(timer);
  617.         for(iL=n/10;iL>0;iL--){
  618.             jL=kL>>1;
  619.             jL=kL>>1;
  620.             jL=kL>>1;
  621.             jL=kL>>1;
  622.             jL=kL>>1;
  623.             jL=kL>>1;
  624.             jL=kL>>1;
  625.             jL=kL>>1;
  626.             jL=kL>>1;
  627.             jL=kL>>1;
  628.         }
  629.         s=StopTimerSecs(timer)/n-overhead;
  630.         ffprintf(o,"%11.3f µs    jL=kL>>1;\n",s*1e6);
  631.     
  632.         StartTimer(timer);
  633.         for(iL=n/10;iL>0;iL--){
  634.             jL=kL+mL;
  635.             jL=kL+mL;
  636.             jL=kL+mL;
  637.             jL=kL+mL;
  638.             jL=kL+mL;
  639.             jL=kL+mL;
  640.             jL=kL+mL;
  641.             jL=kL+mL;
  642.             jL=kL+mL;
  643.             jL=kL+mL;
  644.         }
  645.         s=StopTimerSecs(timer)/n-overhead;
  646.         ffprintf(o,"%11.3f µs    jL=kL+mL;\n",s*1e6);
  647.     
  648.         StartTimer(timer);
  649.         for(iL=n/10;iL>0;iL--){
  650.             jL=kL-mL;
  651.             jL=kL-mL;
  652.             jL=kL-mL;
  653.             jL=kL-mL;
  654.             jL=kL-mL;
  655.             jL=kL-mL;
  656.             jL=kL-mL;
  657.             jL=kL-mL;
  658.             jL=kL-mL;
  659.             jL=kL-mL;
  660.         }
  661.         s=StopTimerSecs(timer)/n-overhead;
  662.         ffprintf(o,"%11.3f µs    jL=kL-mL;\n",s*1e6);
  663.     
  664.         n/=10;            /* all other operations take at least several microseconds */
  665.         StartTimer(timer);
  666.         for(iL=n/10;iL>0;iL--){
  667.             jL=kL*mL;
  668.             jL=kL*mL;
  669.             jL=kL*mL;
  670.             jL=kL*mL;
  671.             jL=kL*mL;
  672.             jL=kL*mL;
  673.             jL=kL*mL;
  674.             jL=kL*mL;
  675.             jL=kL*mL;
  676.             jL=kL*mL;
  677.         }
  678.         s=StopTimerSecs(timer)/n-overhead;
  679.         ffprintf(o,"%11.3f µs    jL=kL*mL;\n",s*1e6);
  680.     
  681.         StartTimer(timer);
  682.         for(iL=n/10;iL>0;iL--){
  683.             jL=kL/mL;
  684.             jL=kL/mL;
  685.             jL=kL/mL;
  686.             jL=kL/mL;
  687.             jL=kL/mL;
  688.             jL=kL/mL;
  689.             jL=kL/mL;
  690.             jL=kL/mL;
  691.             jL=kL/mL;
  692.             jL=kL/mL;
  693.         }
  694.         s=StopTimerSecs(timer)/n-overhead;
  695.         ffprintf(o,"%11.3f µs    jL=kL/mL;\n",s*1e6);
  696.         n*=10;
  697.     }
  698.     if(1){                // time short arithmetic
  699.         register short jH,kH=1234,mH=5678;
  700.         
  701.         StartTimer(timer);
  702.         for(iL=n/10;iL>0;iL--){
  703.             jH=kH;
  704.             jH=kH;
  705.             jH=kH;
  706.             jH=kH;
  707.             jH=kH;
  708.             jH=kH;
  709.             jH=kH;
  710.             jH=kH;
  711.             jH=kH;
  712.             jH=kH;
  713.         }
  714.         s=StopTimerSecs(timer)/n-overhead;
  715.         ffprintf(o,"%11.3f µs    jH=kH;            // short, register to register\n",s*1e6);
  716.     
  717.         StartTimer(timer);
  718.         for(iL=n/10;iL>0;iL--){
  719.             jH=kH>>1;
  720.             jH=kH>>1;
  721.             jH=kH>>1;
  722.             jH=kH>>1;
  723.             jH=kH>>1;
  724.             jH=kH>>1;
  725.             jH=kH>>1;
  726.             jH=kH>>1;
  727.             jH=kH>>1;
  728.             jH=kH>>1;
  729.         }
  730.         s=StopTimerSecs(timer)/n-overhead;
  731.         ffprintf(o,"%11.3f µs    jH=kH>>1;\n",s*1e6);
  732.     
  733.         StartTimer(timer);
  734.         for(iL=n/10;iL>0;iL--){
  735.             jH=kH+mH;
  736.             jH=kH+mH;
  737.             jH=kH+mH;
  738.             jH=kH+mH;
  739.             jH=kH+mH;
  740.             jH=kH+mH;
  741.             jH=kH+mH;
  742.             jH=kH+mH;
  743.             jH=kH+mH;
  744.             jH=kH+mH;
  745.         }
  746.         s=StopTimerSecs(timer)/n-overhead;
  747.         ffprintf(o,"%11.3f µs    jH=kH+mH;\n",s*1e6);
  748.     
  749.         StartTimer(timer);
  750.         for(iL=n/10;iL>0;iL--){
  751.             jH=kH-mH;
  752.             jH=kH-mH;
  753.             jH=kH-mH;
  754.             jH=kH-mH;
  755.             jH=kH-mH;
  756.             jH=kH-mH;
  757.             jH=kH-mH;
  758.             jH=kH-mH;
  759.             jH=kH-mH;
  760.             jH=kH-mH;
  761.         }
  762.         s=StopTimerSecs(timer)/n-overhead;
  763.         ffprintf(o,"%11.3f µs    jH=kH-mH;\n",s*1e6);
  764.     
  765.         n/=10;            /* all other operations take at least several microseconds */
  766.         StartTimer(timer);
  767.         for(iL=n/10;iL>0;iL--){
  768.             jH=kH*mH;
  769.             jH=kH*mH;
  770.             jH=kH*mH;
  771.             jH=kH*mH;
  772.             jH=kH*mH;
  773.             jH=kH*mH;
  774.             jH=kH*mH;
  775.             jH=kH*mH;
  776.             jH=kH*mH;
  777.             jH=kH*mH;
  778.         }
  779.         s=StopTimerSecs(timer)/n-overhead;
  780.         ffprintf(o,"%11.3f µs    jH=kH*mH;\n",s*1e6);
  781.     
  782.         StartTimer(timer);
  783.         for(iL=n/10;iL>0;iL--){
  784.             jH=kH/mH;
  785.             jH=kH/mH;
  786.             jH=kH/mH;
  787.             jH=kH/mH;
  788.             jH=kH/mH;
  789.             jH=kH/mH;
  790.             jH=kH/mH;
  791.             jH=kH/mH;
  792.             jH=kH/mH;
  793.             jH=kH/mH;
  794.         }
  795.         s=StopTimerSecs(timer)/n-overhead;
  796.         ffprintf(o,"%11.3f µs    jH=kH/mH;\n",s*1e6);
  797.         n*=10;
  798.     }
  799.  
  800.     n/=10;            /* all other operations take at least several microseconds */
  801.  
  802.     if(1){        // time double arithmetic
  803.         StartTimer(timer);
  804.         for(iL=n/10;iL>0;iL--){
  805.             x=y;
  806.             x=y;
  807.             x=y;
  808.             x=y;
  809.             x=y;
  810.             x=y;
  811.             x=y;
  812.             x=y;
  813.             x=y;
  814.             x=y;
  815.         }
  816.         s=StopTimerSecs(timer)/n-overhead;
  817.         ffprintf(o,"%11.3f µs    x=y;            // double\n",s*1e6);
  818.     
  819.         StartTimer(timer);
  820.         for(iL=n/10;iL>0;iL--){
  821.             x=y+z;
  822.             x=y+z;
  823.             x=y+z;
  824.             x=y+z;
  825.             x=y+z;
  826.             x=y+z;
  827.             x=y+z;
  828.             x=y+z;
  829.             x=y+z;
  830.             x=y+z;
  831.         }
  832.         s=StopTimerSecs(timer)/n-overhead;
  833.         ffprintf(o,"%11.3f µs    x=y+z;\n",s*1e6);
  834.     
  835.         StartTimer(timer);
  836.         for(iL=n/10;iL>0;iL--){
  837.             x=y-z;
  838.             x=y-z;
  839.             x=y-z;
  840.             x=y-z;
  841.             x=y-z;
  842.             x=y-z;
  843.             x=y-z;
  844.             x=y-z;
  845.             x=y-z;
  846.             x=y-z;
  847.         }
  848.         s=StopTimerSecs(timer)/n-overhead;
  849.         ffprintf(o,"%11.3f µs    x=y-z;\n",s*1e6);
  850.     
  851.         StartTimer(timer);
  852.         for(iL=n/10;iL>0;iL--){
  853.             x=y*z;
  854.             x=y*z;
  855.             x=y*z;
  856.             x=y*z;
  857.             x=y*z;
  858.             x=y*z;
  859.             x=y*z;
  860.             x=y*z;
  861.             x=y*z;
  862.             x=y*z;
  863.         }
  864.         s=StopTimerSecs(timer)/n-overhead;
  865.         ffprintf(o,"%11.3f µs    x=y*z;\n",s*1e6);
  866.     
  867.         StartTimer(timer);
  868.         for(iL=n/10;iL>0;iL--){
  869.             x=y/z;
  870.             x=y/z;
  871.             x=y/z;
  872.             x=y/z;
  873.             x=y/z;
  874.             x=y/z;
  875.             x=y/z;
  876.             x=y/z;
  877.             x=y/z;
  878.             x=y/z;
  879.         }
  880.         s=StopTimerSecs(timer)/n-overhead;
  881.         ffprintf(o,"%11.3f µs    x=y/z;\n",s*1e6);
  882.     }
  883.     
  884.     if(1){                // time transcendental functions
  885.         StartTimer(timer);
  886.         for(iL=n/10;iL>0;iL--){
  887.             x=sin(y);
  888.             x=sin(y);
  889.             x=sin(y);
  890.             x=sin(y);
  891.             x=sin(y);
  892.             x=sin(y);
  893.             x=sin(y);
  894.             x=sin(y);
  895.             x=sin(y);
  896.             x=sin(y);
  897.         }
  898.         s=StopTimerSecs(timer)/n-overhead;
  899.         ffprintf(o,"%11.3f µs    x=sin(y);\n",s*1e6);
  900.     
  901.         StartTimer(timer);
  902.         for(iL=n/10;iL>0;iL--){
  903.             x=sqrt(y);
  904.             x=sqrt(y);
  905.             x=sqrt(y);
  906.             x=sqrt(y);
  907.             x=sqrt(y);
  908.             x=sqrt(y);
  909.             x=sqrt(y);
  910.             x=sqrt(y);
  911.             x=sqrt(y);
  912.             x=sqrt(y);
  913.         }
  914.         s=StopTimerSecs(timer)/n-overhead;
  915.         ffprintf(o,"%11.3f µs    x=sqrt(y);\n",s*1e6);
  916.     
  917.         n/=100;
  918.         StartTimer(timer);
  919.         for(iL=n/10;iL>0;iL--){
  920.             x=log(y);
  921.             x=log(y);
  922.             x=log(y);
  923.             x=log(y);
  924.             x=log(y);
  925.             x=log(y);
  926.             x=log(y);
  927.             x=log(y);
  928.             x=log(y);
  929.             x=log(y);
  930.         }
  931.         s=StopTimerSecs(timer)/n-overhead;
  932.         ffprintf(o,"%11.3f µs    x=log(y);\n",s*1e6);
  933.         StartTimer(timer);
  934.         for(iL=n/10;iL>0;iL--){
  935.             x=exp(y);
  936.             x=exp(y);
  937.             x=exp(y);
  938.             x=exp(y);
  939.             x=exp(y);
  940.             x=exp(y);
  941.             x=exp(y);
  942.             x=exp(y);
  943.             x=exp(y);
  944.             x=exp(y);
  945.         }
  946.         s=StopTimerSecs(timer)/n-overhead;
  947.         ffprintf(o,"%11.3f µs    x=exp(y);\n",s*1e6);
  948.         n*=100;
  949.     
  950.     }
  951.  
  952.     o[1]=NULL;        /* that's all we want to save in “TimeCPU results” */
  953.  
  954.     if(1){                    // time Fixed
  955.         yF=zF=0x12341234;
  956.         StartTimer(timer);
  957.         for(iL=n/10;iL>0;iL--){
  958.             xF=FixMul(yF,zF);
  959.             xF=FixMul(yF,zF);
  960.             xF=FixMul(yF,zF);
  961.             xF=FixMul(yF,zF);
  962.             xF=FixMul(yF,zF);
  963.             xF=FixMul(yF,zF);
  964.             xF=FixMul(yF,zF);
  965.             xF=FixMul(yF,zF);
  966.             xF=FixMul(yF,zF);
  967.             xF=FixMul(yF,zF);
  968.         }
  969.         s=StopTimerSecs(timer)/n-overhead;
  970.         ffprintf(o,"%11.3f µs    xF=FixMul(yF,zF);    // Fixed\n",s*1e6);
  971.     
  972.         yF=(long)(PI*256);
  973.         zF=(long)(1.1*256);
  974.         StartTimer(timer);
  975.         for(iL=n/10;iL>0;iL--){
  976.             xF=FixDiv(yF,zF);
  977.             xF=FixDiv(yF,zF);
  978.             xF=FixDiv(yF,zF);
  979.             xF=FixDiv(yF,zF);
  980.             xF=FixDiv(yF,zF);
  981.             xF=FixDiv(yF,zF);
  982.             xF=FixDiv(yF,zF);
  983.             xF=FixDiv(yF,zF);
  984.             xF=FixDiv(yF,zF);
  985.             xF=FixDiv(yF,zF);
  986.         }
  987.         s=StopTimerSecs(timer)/n-overhead;
  988.         ffprintf(o,"%11.3f µs    xF=FixDiv(yF,zF);\n",s*1e6);
  989.     
  990.         StartTimer(timer);
  991.         for(iL=n/10;iL>0;iL--){
  992.             xF=FixRatio(123,1234);
  993.             xF=FixRatio(123,1234);
  994.             xF=FixRatio(123,1234);
  995.             xF=FixRatio(123,1234);
  996.             xF=FixRatio(123,1234);
  997.             xF=FixRatio(123,1234);
  998.             xF=FixRatio(123,1234);
  999.             xF=FixRatio(123,1234);
  1000.             xF=FixRatio(123,1234);
  1001.             xF=FixRatio(123,1234);
  1002.         }
  1003.         s=StopTimerSecs(timer)/n-overhead;
  1004.         ffprintf(o,"%11.3f µs    xF=FixRatio(123,1234);\n",s*1e6);
  1005.     
  1006.         StartTimer(timer);
  1007.         for(iL=n/10;iL>0;iL--){
  1008.             xF=DoubleToFix(y);
  1009.             xF=DoubleToFix(y);
  1010.             xF=DoubleToFix(y);
  1011.             xF=DoubleToFix(y);
  1012.             xF=DoubleToFix(y);
  1013.             xF=DoubleToFix(y);
  1014.             xF=DoubleToFix(y);
  1015.             xF=DoubleToFix(y);
  1016.             xF=DoubleToFix(y);
  1017.             xF=DoubleToFix(y);
  1018.         }
  1019.         s=StopTimerSecs(timer)/n-overhead;
  1020.         ffprintf(o,"%11.3f µs    xF=DoubleToFix(y);\n",s*1e6);
  1021.     
  1022.         xF=(long)(PI*256);
  1023.         StartTimer(timer);
  1024.         for(iL=n/10;iL>0;iL--){
  1025.             x=FixToDouble(xF);
  1026.             x=FixToDouble(xF);
  1027.             x=FixToDouble(xF);
  1028.             x=FixToDouble(xF);
  1029.             x=FixToDouble(xF);
  1030.             x=FixToDouble(xF);
  1031.             x=FixToDouble(xF);
  1032.             x=FixToDouble(xF);
  1033.             x=FixToDouble(xF);
  1034.             x=FixToDouble(xF);
  1035.             x=FixToDouble(xF);
  1036.         }
  1037.         s=StopTimerSecs(timer)/n-overhead;
  1038.         ffprintf(o,"%11.3f µs    x=FixToDouble(xF);\n",s*1e6);
  1039.     }
  1040.     
  1041.     if(1){                // time rand()
  1042.         n*=10;
  1043.         for(;n>0;){
  1044.             bufferHandle=NewHandle(n);
  1045.             if(bufferHandle==NULL)bufferHandle=TempNewHandle(n,&osErr);
  1046.             if(bufferHandle!=NULL)break;
  1047.             n/=2;
  1048.             printf("Reducing iterations to %ld to fit in available memory.\n",n);
  1049.         }
  1050.         assert(bufferHandle!=NULL);
  1051.         HLockHi(bufferHandle);
  1052.         buffer=*bufferHandle;
  1053.         StartTimer(timer);
  1054.         s=StopTimerSecs(timer);
  1055.         StartTimer(timer);
  1056.         RandFill(buffer,n);
  1057.         s=StopTimerSecs(timer) - s;
  1058.         DisposeHandle(bufferHandle);
  1059.         buffer=NULL;
  1060.         ffprintf(o,"%11.3f µs    RandFill(,%ld);    // i.e. %4.1f µs/byte\n"
  1061.             ,s*1e6,n,s*1e6/n);
  1062.         n/=10;
  1063.     
  1064.         StartTimer(timer);
  1065.         for(iL=n/10;iL>0;iL--){
  1066.             i=randU();
  1067.             i=randU();
  1068.             i=randU();
  1069.             i=randU();
  1070.             i=randU();
  1071.             i=randU();
  1072.             i=randU();
  1073.             i=randU();
  1074.             i=randU();
  1075.             i=randU();
  1076.         }
  1077.         s=StopTimerSecs(timer)/n-overhead;
  1078.         ffprintf(o,"%11.3f µs    i=randU();        // i.e. %4.1f µs/byte\n",s*1e6, s*1e6/2.);
  1079.     
  1080.         StartTimer(timer);
  1081.         for(iL=n/10;iL>0;iL--){
  1082.             i=rand();
  1083.             i=rand();
  1084.             i=rand();
  1085.             i=rand();
  1086.             i=rand();
  1087.             i=rand();
  1088.             i=rand();
  1089.             i=rand();
  1090.             i=rand();
  1091.             i=rand();
  1092.         }
  1093.         s=StopTimerSecs(timer)/n-overhead;
  1094.         ffprintf(o,"%11.3f µs    i=rand();         // i.e. %4.1f µs/byte\n",s*1e6, s*1e6/1.);
  1095.     
  1096.         StartTimer(timer);
  1097.         for(iL=n/10;iL>0;iL--){
  1098.             i=Random();
  1099.             i=Random();
  1100.             i=Random();
  1101.             i=Random();
  1102.             i=Random();
  1103.             i=Random();
  1104.             i=Random();
  1105.             i=Random();
  1106.             i=Random();
  1107.             i=Random();
  1108.         }
  1109.         s=StopTimerSecs(timer)/n-overhead;
  1110.         ffprintf(o,"%11.3f µs    i=Random();\n",s*1e6);
  1111.     
  1112.         StartTimer(timer);
  1113.         for(iL=n/10;iL>0;iL--){
  1114.             i=nrand(127);
  1115.             i=nrand(127);
  1116.             i=nrand(127);
  1117.             i=nrand(127);
  1118.             i=nrand(127);
  1119.             i=nrand(127);
  1120.             i=nrand(127);
  1121.             i=nrand(127);
  1122.             i=nrand(127);
  1123.             i=nrand(127);
  1124.         }
  1125.         s=StopTimerSecs(timer)/n-overhead;
  1126.         ffprintf(o,"%11.3f µs    i=nrand(127);\n",s*1e6);
  1127.     
  1128.         StartTimer(timer);
  1129.         for(iL=n/10;iL>0;iL--){
  1130.             i=127L*randU()>>16;
  1131.             i=127L*randU()>>16;
  1132.             i=127L*randU()>>16;
  1133.             i=127L*randU()>>16;
  1134.             i=127L*randU()>>16;
  1135.             i=127L*randU()>>16;
  1136.             i=127L*randU()>>16;
  1137.             i=127L*randU()>>16;
  1138.             i=127L*randU()>>16;
  1139.             i=127L*randU()>>16;
  1140.         }
  1141.         s=StopTimerSecs(timer)/n-overhead;
  1142.         ffprintf(o,"%11.3f µs    i=127L*randU()>>16;\n",s*1e6);
  1143.     
  1144.         StartTimer(timer);
  1145.         for(iL=n/10;iL>0;iL--){
  1146.             i=127L*rand()>>15;
  1147.             i=127L*rand()>>15;
  1148.             i=127L*rand()>>15;
  1149.             i=127L*rand()>>15;
  1150.             i=127L*rand()>>15;
  1151.             i=127L*rand()>>15;
  1152.             i=127L*rand()>>15;
  1153.             i=127L*rand()>>15;
  1154.             i=127L*rand()>>15;
  1155.             i=127L*rand()>>15;
  1156.         }
  1157.         s=StopTimerSecs(timer)/n-overhead;
  1158.         ffprintf(o,"%11.3f µs    i=127L*rand()>>15;\n",s*1e6);
  1159.     
  1160.         StartTimer(timer);
  1161.         for(iL=n/10;iL>0;iL--){
  1162.             i=randU()%(unsigned short)127;
  1163.             i=randU()%(unsigned short)127;
  1164.             i=randU()%(unsigned short)127;
  1165.             i=randU()%(unsigned short)127;
  1166.             i=randU()%(unsigned short)127;
  1167.             i=randU()%(unsigned short)127;
  1168.             i=randU()%(unsigned short)127;
  1169.             i=randU()%(unsigned short)127;
  1170.             i=randU()%(unsigned short)127;
  1171.             i=randU()%(unsigned short)127;
  1172.         }
  1173.         s=StopTimerSecs(timer)/n-overhead;
  1174.         ffprintf(o,"%11.3f µs    i=randU()%%(unsigned short)127;\n",s*1e6);
  1175.     
  1176.         StartTimer(timer);
  1177.         for(iL=n/10;iL>0;iL--){
  1178.             i=rand()%127;
  1179.             i=rand()%127;
  1180.             i=rand()%127;
  1181.             i=rand()%127;
  1182.             i=rand()%127;
  1183.             i=rand()%127;
  1184.             i=rand()%127;
  1185.             i=rand()%127;
  1186.             i=rand()%127;
  1187.             i=rand()%127;
  1188.         }
  1189.         s=StopTimerSecs(timer)/n-overhead;
  1190.         ffprintf(o,"%11.3f µs    i=rand()%%127;\n",s*1e6);
  1191.     }
  1192.     DisposeTimer(timer);
  1193.     fclose(dataFile);    /* close “TimeCPU results” */
  1194.     DrawMenuBar();
  1195. }
  1196.  
  1197.